import UtilsContrast, {IUtilsContrast} from './index';

describe('UtilsContrast', () => {
    let utilsContrast: IUtilsContrast;

    beforeEach(() => {
        utilsContrast = UtilsContrast;
    });

    test('version should return true when server version is greater', () => {
        const serverVersion = '2.0.1';
        const localVersion = '1.0.0';
        expect(utilsContrast.version(serverVersion, localVersion)).toBe(true);
    });

    test('version should return false when server version is equal', () => {
        const serverVersion = '1.0.0';
        const localVersion = '1.0.0';
        expect(utilsContrast.version(serverVersion, localVersion)).toBe(false);
    });

    test('version should return false when server version is less', () => {
        const serverVersion = '1.0.0';
        const localVersion = '2.0.1';
        expect(utilsContrast.version(serverVersion, localVersion)).toBe(false);
    });

    test('json should return true when two JSON objects are equal', () => {
        const jsonOne = {name: 'John'};
        const jsonTwo = {name: 'John'};
        expect(utilsContrast.json(jsonOne, jsonTwo)).toBe(true);
    });

    test('json should return false when two JSON objects are not equal', () => {
        const jsonOne = {name: 'John'};
        const jsonTwo = {name: 'Jane'};
        expect(utilsContrast.json(jsonOne, jsonTwo)).toBe(false);
    });

    test('jsonToDiff should return an empty object when old and new JSON are equal', () => {
        const oldJson = {name: 'John'};
        const newJson = {name: 'John'};
        expect(utilsContrast.jsonToDiff(oldJson, newJson)).toEqual({});
    });

    test('jsonToDiff should return the difference when old and new JSON are not equal', () => {
        const oldJson = {name: 'John'};
        const newJson = {name: 'Jane'};
        expect(utilsContrast.jsonToDiff(oldJson, newJson)).toEqual({name: 'Jane'});
    });

    test('arrayToDiff should return the correct result when arrays have differences', () => {
        const oldArr = [1, 2, 3];
        const newArr = [2, 3, 4];
        const result = utilsContrast.arrayToDiff(oldArr, newArr);
        expect(result.oldDiff).toEqual([1]);
        expect(result.newDiff).toEqual([4]);
    });

    test('arrayToDiff should return an empty result when arrays are equal', () => {
        const oldArr = [1, 2, 3];
        const newArr = [1, 2, 3];
        const result = utilsContrast.arrayToDiff(oldArr, newArr);
        expect(result.oldDiff).toEqual([]);
        expect(result.newDiff).toEqual([]);
    });
});
